using System.Diagnostics;

namespace XyNet
{

public abstract class BaseService : XyNet.RpcService
{

	public class SendErrorMethod : XyNet.RpcMethod
	{
		using Request = BaseServiceMessage.SendErrorRequest;
		using Response = BaseServiceMessage.SendErrorResponse;

		using Controller = XyNet.RpcController;

		public class Argument : XyNet.RpcArgument
		{
			public Argument() : base(new Request(), new Response()) {}

			public new Controller Controller { get { return _controller as Controller; } }
			public new Request Request { get { return _request as Request; } }
			public new Response Response { get { return _response as Response; } }

			public MessageParser<Request> RequestParser { get { return Request.Parser; } }
			public MessageParser<Response> ResponseParser { get { return Response.Parser; } }

			private override XyNet.RpcArgument clone();
			private override void initializeController(XyNet.RpcSocketChannel socketChannel);
		};

		public class Callback : XyNet.RpcCallback
		{
			public delegate void ResponseDelegate(Argument argument);
			public delegate void ExceptionDelegate(Argument argument);

			public Callback(XyNet.RpcArgument argument, ResponseDelegate responseHandler, ExceptionDelegate exceptionHandler)
				: base(argument) { _responseHandler = responseHandler; _exceptionHandler = exceptionHandler; }

			public override void DoResponseHandler()
			{
				if (_responseHandler != null)
					_responseHandler(Argument as Argument);
			}

			public override void DoExceptionHandler()
			{
				if (_exceptionHandler != null)
					_exceptionHandler(Argument as Argument);
				else
					Common.CException.HandleException(new System.Exception(Argument.Controller.ErrorText));
			}

			private ResponseDelegate _responseHandler;
			private ExceptionDelegate _exceptionHandler;
		}

		public SendErrorMethod(IRpcChannel channel) : base("SendError", 0x5ED90F27, 0x7353EF39), _argument(new Argument) {}

		public Request Request { get { return _argument.Request as Request; } }

		public void Call(
			Callback.ResponseDelegate responseHandler = null,
			Callback.ExceptionDelegate exceptionHandler = null)
		{
			channel.CallMethod(this, new Callback(_argument, responseHandler, exceptionHandler));
		}
	}

	public abstract void SendError(SendErrorMethod.Argument argument);

	public class SendHeartBeatMethod : XyNet.RpcMethod
	{
		using Request = BaseServiceMessage.SendHeartBeatRequest;
		using Response = BaseServiceMessage.SendHeartBeatResponse;

		using Controller = XyNet.RpcController;

		public class Argument : XyNet.RpcArgument
		{
			public Argument() : base(new Request(), new Response()) {}

			public new Controller Controller { get { return _controller as Controller; } }
			public new Request Request { get { return _request as Request; } }
			public new Response Response { get { return _response as Response; } }

			public MessageParser<Request> RequestParser { get { return Request.Parser; } }
			public MessageParser<Response> ResponseParser { get { return Response.Parser; } }

			private override XyNet.RpcArgument clone();
			private override void initializeController(XyNet.RpcSocketChannel socketChannel);
		};

		public class Callback : XyNet.RpcCallback
		{
			public delegate void ResponseDelegate(Argument argument);
			public delegate void ExceptionDelegate(Argument argument);

			public Callback(XyNet.RpcArgument argument, ResponseDelegate responseHandler, ExceptionDelegate exceptionHandler)
				: base(argument) { _responseHandler = responseHandler; _exceptionHandler = exceptionHandler; }

			public override void DoResponseHandler()
			{
				if (_responseHandler != null)
					_responseHandler(Argument as Argument);
			}

			public override void DoExceptionHandler()
			{
				if (_exceptionHandler != null)
					_exceptionHandler(Argument as Argument);
				else
					Common.CException.HandleException(new System.Exception(Argument.Controller.ErrorText));
			}

			private ResponseDelegate _responseHandler;
			private ExceptionDelegate _exceptionHandler;
		}

		public SendHeartBeatMethod(IRpcChannel channel) : base("SendHeartBeat", 0xFBCBDC1F, 0x7353EF39), _argument(new Argument) {}

		public Request Request { get { return _argument.Request as Request; } }

		public void Call(
			Callback.ResponseDelegate responseHandler = null,
			Callback.ExceptionDelegate exceptionHandler = null)
		{
			channel.CallMethod(this, new Callback(_argument, responseHandler, exceptionHandler));
		}
	}

	public abstract void SendHeartBeat(SendHeartBeatMethod.Argument argument);

	public class GetUtcTimeMethod : XyNet.RpcMethod
	{
		using Request = BaseServiceMessage.GetUtcTimeRequest;
		using Response = BaseServiceMessage.GetUtcTimeResponse;

		using Controller = XyNet.RpcController;

		public class Argument : XyNet.RpcArgument
		{
			public Argument() : base(new Request(), new Response()) {}

			public new Controller Controller { get { return _controller as Controller; } }
			public new Request Request { get { return _request as Request; } }
			public new Response Response { get { return _response as Response; } }

			public MessageParser<Request> RequestParser { get { return Request.Parser; } }
			public MessageParser<Response> ResponseParser { get { return Response.Parser; } }

			private override XyNet.RpcArgument clone();
			private override void initializeController(XyNet.RpcSocketChannel socketChannel);
		};

		public class Callback : XyNet.RpcCallback
		{
			public delegate void ResponseDelegate(Argument argument);
			public delegate void ExceptionDelegate(Argument argument);

			public Callback(XyNet.RpcArgument argument, ResponseDelegate responseHandler, ExceptionDelegate exceptionHandler)
				: base(argument) { _responseHandler = responseHandler; _exceptionHandler = exceptionHandler; }

			public override void DoResponseHandler()
			{
				if (_responseHandler != null)
					_responseHandler(Argument as Argument);
			}

			public override void DoExceptionHandler()
			{
				if (_exceptionHandler != null)
					_exceptionHandler(Argument as Argument);
				else
					Common.CException.HandleException(new System.Exception(Argument.Controller.ErrorText));
			}

			private ResponseDelegate _responseHandler;
			private ExceptionDelegate _exceptionHandler;
		}

		public GetUtcTimeMethod(IRpcChannel channel) : base("GetUtcTime", 0x13432C70, 0x7353EF39), _argument(new Argument) {}

		public Request Request { get { return _argument.Request as Request; } }

		public void Call(
			Callback.ResponseDelegate responseHandler = null,
			Callback.ExceptionDelegate exceptionHandler = null)
		{
			channel.CallMethod(this, new Callback(_argument, responseHandler, exceptionHandler));
		}
	}

	public abstract void GetUtcTime(GetUtcTimeMethod.Argument argument);

	public class GetBrokerQueriesMethod : XyNet.RpcMethod
	{
		using Request = BaseServiceMessage.GetBrokerQueriesRequest;
		using Response = BaseServiceMessage.GetBrokerQueriesResponse;

		using Controller = XyNet.RpcController;

		public class Argument : XyNet.RpcArgument
		{
			public Argument() : base(new Request(), new Response()) {}

			public new Controller Controller { get { return _controller as Controller; } }
			public new Request Request { get { return _request as Request; } }
			public new Response Response { get { return _response as Response; } }

			public MessageParser<Request> RequestParser { get { return Request.Parser; } }
			public MessageParser<Response> ResponseParser { get { return Response.Parser; } }

			private override XyNet.RpcArgument clone();
			private override void initializeController(XyNet.RpcSocketChannel socketChannel);
		};

		public class Callback : XyNet.RpcCallback
		{
			public delegate void ResponseDelegate(Argument argument);
			public delegate void ExceptionDelegate(Argument argument);

			public Callback(XyNet.RpcArgument argument, ResponseDelegate responseHandler, ExceptionDelegate exceptionHandler)
				: base(argument) { _responseHandler = responseHandler; _exceptionHandler = exceptionHandler; }

			public override void DoResponseHandler()
			{
				if (_responseHandler != null)
					_responseHandler(Argument as Argument);
			}

			public override void DoExceptionHandler()
			{
				if (_exceptionHandler != null)
					_exceptionHandler(Argument as Argument);
				else
					Common.CException.HandleException(new System.Exception(Argument.Controller.ErrorText));
			}

			private ResponseDelegate _responseHandler;
			private ExceptionDelegate _exceptionHandler;
		}

		public GetBrokerQueriesMethod(IRpcChannel channel) : base("GetBrokerQueries", 0x88D76562, 0x7353EF39), _argument(new Argument) {}

		public Request Request { get { return _argument.Request as Request; } }

		public void Call(
			Callback.ResponseDelegate responseHandler = null,
			Callback.ExceptionDelegate exceptionHandler = null)
		{
			channel.CallMethod(this, new Callback(_argument, responseHandler, exceptionHandler));
		}
	}

	public abstract void GetBrokerQueries(GetBrokerQueriesMethod.Argument argument);

	public BaseService() : base("BaseService", 0x7353EF39) {}

	public override XyNet.RpcArgument CreateMethodArgument(int methodId)
		case 5ED90F27:
			return new SendErrorMethod.Argument();
		case FBCBDC1F:
			return new SendHeartBeatMethod.Argument();
		case 13432C70:
			return new GetUtcTimeMethod.Argument();
		case 88D76562:
			return new GetBrokerQueriesMethod.Argument();
		default:
			Debug.Assert(false);
			return null;
		}
	}

	public override void CallMethod(int methodIndex, XyNet.RpcArgument argument)
	{
		switch (methodIndex)
		{
		case 5ED90F27:
			SendError(argument as SendErrorMethod.Argument);
			break;
		case FBCBDC1F:
			SendHeartBeat(argument as SendHeartBeatMethod.Argument);
			break;
		case 13432C70:
			GetUtcTime(argument as GetUtcTimeMethod.Argument);
			break;
		case 88D76562:
			GetBrokerQueries(argument as GetBrokerQueriesMethod.Argument);
			break;
			default:
				Debug.Assert(false);
				break;
			}
		}
	}
}

public abstract class DownloadService : XyNet.RpcService
{

	public class GetResourceInfoMethod : XyNet.RpcMethod
	{
		using Request = DownloadServiceMessage.GetResourceInfoRequest;
		using Response = DownloadServiceMessage.GetResourceInfoResponse;

		using Controller = XyNet.RpcController;

		public class Argument : XyNet.RpcArgument
		{
			public Argument() : base(new Request(), new Response()) {}

			public new Controller Controller { get { return _controller as Controller; } }
			public new Request Request { get { return _request as Request; } }
			public new Response Response { get { return _response as Response; } }

			public MessageParser<Request> RequestParser { get { return Request.Parser; } }
			public MessageParser<Response> ResponseParser { get { return Response.Parser; } }

			private override XyNet.RpcArgument clone();
			private override void initializeController(XyNet.RpcSocketChannel socketChannel);
		};

		public class Callback : XyNet.RpcCallback
		{
			public delegate void ResponseDelegate(Argument argument);
			public delegate void ExceptionDelegate(Argument argument);

			public Callback(XyNet.RpcArgument argument, ResponseDelegate responseHandler, ExceptionDelegate exceptionHandler)
				: base(argument) { _responseHandler = responseHandler; _exceptionHandler = exceptionHandler; }

			public override void DoResponseHandler()
			{
				if (_responseHandler != null)
					_responseHandler(Argument as Argument);
			}

			public override void DoExceptionHandler()
			{
				if (_exceptionHandler != null)
					_exceptionHandler(Argument as Argument);
				else
					Common.CException.HandleException(new System.Exception(Argument.Controller.ErrorText));
			}

			private ResponseDelegate _responseHandler;
			private ExceptionDelegate _exceptionHandler;
		}

		public GetResourceInfoMethod(IRpcChannel channel) : base("GetResourceInfo", 0x9B947791, 0x78FF2E9D), _argument(new Argument) {}

		public Request Request { get { return _argument.Request as Request; } }

		public void Call(
			Callback.ResponseDelegate responseHandler = null,
			Callback.ExceptionDelegate exceptionHandler = null)
		{
			channel.CallMethod(this, new Callback(_argument, responseHandler, exceptionHandler));
		}
	}

	public abstract void GetResourceInfo(GetResourceInfoMethod.Argument argument);

	public class GetFileDataMethod : XyNet.RpcMethod
	{
		using Request = DownloadServiceMessage.GetFileDataRequest;
		using Response = DownloadServiceMessage.GetFileDataResponse;

		using Controller = XyNet.RpcController;

		public class Argument : XyNet.RpcArgument
		{
			public Argument() : base(new Request(), new Response()) {}

			public new Controller Controller { get { return _controller as Controller; } }
			public new Request Request { get { return _request as Request; } }
			public new Response Response { get { return _response as Response; } }

			public MessageParser<Request> RequestParser { get { return Request.Parser; } }
			public MessageParser<Response> ResponseParser { get { return Response.Parser; } }

			private override XyNet.RpcArgument clone();
			private override void initializeController(XyNet.RpcSocketChannel socketChannel);
		};

		public class Callback : XyNet.RpcCallback
		{
			public delegate void ResponseDelegate(Argument argument);
			public delegate void ExceptionDelegate(Argument argument);

			public Callback(XyNet.RpcArgument argument, ResponseDelegate responseHandler, ExceptionDelegate exceptionHandler)
				: base(argument) { _responseHandler = responseHandler; _exceptionHandler = exceptionHandler; }

			public override void DoResponseHandler()
			{
				if (_responseHandler != null)
					_responseHandler(Argument as Argument);
			}

			public override void DoExceptionHandler()
			{
				if (_exceptionHandler != null)
					_exceptionHandler(Argument as Argument);
				else
					Common.CException.HandleException(new System.Exception(Argument.Controller.ErrorText));
			}

			private ResponseDelegate _responseHandler;
			private ExceptionDelegate _exceptionHandler;
		}

		public GetFileDataMethod(IRpcChannel channel) : base("GetFileData", 0x6C96C8FD, 0x78FF2E9D), _argument(new Argument) {}

		public Request Request { get { return _argument.Request as Request; } }

		public void Call(
			Callback.ResponseDelegate responseHandler = null,
			Callback.ExceptionDelegate exceptionHandler = null)
		{
			channel.CallMethod(this, new Callback(_argument, responseHandler, exceptionHandler));
		}
	}

	public abstract void GetFileData(GetFileDataMethod.Argument argument);

	public DownloadService() : base("DownloadService", 0x78FF2E9D) {}

	public override XyNet.RpcArgument CreateMethodArgument(int methodId)
		case 9B947791:
			return new GetResourceInfoMethod.Argument();
		case 6C96C8FD:
			return new GetFileDataMethod.Argument();
		default:
			Debug.Assert(false);
			return null;
		}
	}

	public override void CallMethod(int methodIndex, XyNet.RpcArgument argument)
	{
		switch (methodIndex)
		{
		case 9B947791:
			GetResourceInfo(argument as GetResourceInfoMethod.Argument);
			break;
		case 6C96C8FD:
			GetFileData(argument as GetFileDataMethod.Argument);
			break;
			default:
				Debug.Assert(false);
				break;
			}
		}
	}
}

public abstract class UploadService : XyNet.RpcService
{

	public class CreateUploadTaskMethod : XyNet.RpcMethod
	{
		using Request = UploadServiceMessage.CreateUploadTaskRequest;
		using Response = UploadServiceMessage.CreateUploadTaskResponse;

		using Controller = XyNet.RpcController;

		public class Argument : XyNet.RpcArgument
		{
			public Argument() : base(new Request(), new Response()) {}

			public new Controller Controller { get { return _controller as Controller; } }
			public new Request Request { get { return _request as Request; } }
			public new Response Response { get { return _response as Response; } }

			public MessageParser<Request> RequestParser { get { return Request.Parser; } }
			public MessageParser<Response> ResponseParser { get { return Response.Parser; } }

			private override XyNet.RpcArgument clone();
			private override void initializeController(XyNet.RpcSocketChannel socketChannel);
		};

		public class Callback : XyNet.RpcCallback
		{
			public delegate void ResponseDelegate(Argument argument);
			public delegate void ExceptionDelegate(Argument argument);

			public Callback(XyNet.RpcArgument argument, ResponseDelegate responseHandler, ExceptionDelegate exceptionHandler)
				: base(argument) { _responseHandler = responseHandler; _exceptionHandler = exceptionHandler; }

			public override void DoResponseHandler()
			{
				if (_responseHandler != null)
					_responseHandler(Argument as Argument);
			}

			public override void DoExceptionHandler()
			{
				if (_exceptionHandler != null)
					_exceptionHandler(Argument as Argument);
				else
					Common.CException.HandleException(new System.Exception(Argument.Controller.ErrorText));
			}

			private ResponseDelegate _responseHandler;
			private ExceptionDelegate _exceptionHandler;
		}

		public CreateUploadTaskMethod(IRpcChannel channel) : base("CreateUploadTask", 0x5AA135B1, 0x805F4CE9), _argument(new Argument) {}

		public Request Request { get { return _argument.Request as Request; } }

		public void Call(
			Callback.ResponseDelegate responseHandler = null,
			Callback.ExceptionDelegate exceptionHandler = null)
		{
			channel.CallMethod(this, new Callback(_argument, responseHandler, exceptionHandler));
		}
	}

	public abstract void CreateUploadTask(CreateUploadTaskMethod.Argument argument);

	public class GetUploadInfoMethod : XyNet.RpcMethod
	{
		using Request = UploadServiceMessage.GetUploadInfoRequest;
		using Response = UploadServiceMessage.GetUploadInfoResponse;

		using Controller = XyNet.RpcController;

		public class Argument : XyNet.RpcArgument
		{
			public Argument() : base(new Request(), new Response()) {}

			public new Controller Controller { get { return _controller as Controller; } }
			public new Request Request { get { return _request as Request; } }
			public new Response Response { get { return _response as Response; } }

			public MessageParser<Request> RequestParser { get { return Request.Parser; } }
			public MessageParser<Response> ResponseParser { get { return Response.Parser; } }

			private override XyNet.RpcArgument clone();
			private override void initializeController(XyNet.RpcSocketChannel socketChannel);
		};

		public class Callback : XyNet.RpcCallback
		{
			public delegate void ResponseDelegate(Argument argument);
			public delegate void ExceptionDelegate(Argument argument);

			public Callback(XyNet.RpcArgument argument, ResponseDelegate responseHandler, ExceptionDelegate exceptionHandler)
				: base(argument) { _responseHandler = responseHandler; _exceptionHandler = exceptionHandler; }

			public override void DoResponseHandler()
			{
				if (_responseHandler != null)
					_responseHandler(Argument as Argument);
			}

			public override void DoExceptionHandler()
			{
				if (_exceptionHandler != null)
					_exceptionHandler(Argument as Argument);
				else
					Common.CException.HandleException(new System.Exception(Argument.Controller.ErrorText));
			}

			private ResponseDelegate _responseHandler;
			private ExceptionDelegate _exceptionHandler;
		}

		public GetUploadInfoMethod(IRpcChannel channel) : base("GetUploadInfo", 0x3EA04181, 0x805F4CE9), _argument(new Argument) {}

		public Request Request { get { return _argument.Request as Request; } }

		public void Call(
			Callback.ResponseDelegate responseHandler = null,
			Callback.ExceptionDelegate exceptionHandler = null)
		{
			channel.CallMethod(this, new Callback(_argument, responseHandler, exceptionHandler));
		}
	}

	public abstract void GetUploadInfo(GetUploadInfoMethod.Argument argument);

	public UploadService() : base("UploadService", 0x805F4CE9) {}

	public override XyNet.RpcArgument CreateMethodArgument(int methodId)
		case 5AA135B1:
			return new CreateUploadTaskMethod.Argument();
		case 3EA04181:
			return new GetUploadInfoMethod.Argument();
		default:
			Debug.Assert(false);
			return null;
		}
	}

	public override void CallMethod(int methodIndex, XyNet.RpcArgument argument)
	{
		switch (methodIndex)
		{
		case 5AA135B1:
			CreateUploadTask(argument as CreateUploadTaskMethod.Argument);
			break;
		case 3EA04181:
			GetUploadInfo(argument as GetUploadInfoMethod.Argument);
			break;
			default:
				Debug.Assert(false);
				break;
			}
		}
	}
}

}
